package com.runewbie.pafcmall.search.controller;

import com.runewbie.pafcmall.search.service.MallSearchService;
import com.runewbie.pafcmall.search.vo.SearchParam;
import com.runewbie.pafcmall.search.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @author: li_jian
 * @version: 1.0
 * @date: 2020/6/22 23:11
 * @description： 搜索页控制器类
 */
@Controller
public class SearchController {

    @Autowired
    MallSearchService mallSearchService;

    /**
     * 跳转到检索页
     *
     * 自动将页面提交的所有请求查询参数封装成指定的对象
     * @param param
     * @return
     */
    @GetMapping("/list.html")
    public String listPage(SearchParam param, Model model, HttpServletRequest request){

        // 获取浏览器的url请求地址
        String queryString = request.getQueryString();
        param.set_queryString(queryString);
        //1、根据传递过来的页面查询参数，去es中检索商品
        SearchResult result = mallSearchService.search(param);
        model.addAttribute("result", result);

        return "list";
    }
}
